package com.nexus.all.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.all.enums.FileStatusEnum;
import com.nexus.all.dao.FileBatchMapper;
import com.nexus.all.model.FileBatch;
import com.nexus.bean.utils.CollectionsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文件上传批次表管理类
 *
 * @author zxt
 * @version 1.0
 * @CopyRright (c): <?>
 */
@Slf4j
@Service
public class FileBatchManager extends ServiceImpl<FileBatchMapper, FileBatch> {


    public List<FileBatch> getByPendingFileBatch() {
        LambdaQueryWrapper<FileBatch> wrapper = FileBatch.gw();
        wrapper.in(FileBatch::getFileStatus, CollectionsUtil.asList(FileStatusEnum.PENDING.getValue(), FileStatusEnum.FAIL.getValue()));
        return list(wrapper);
    }

    public boolean updateStatus(Long id, Byte fileStatus, List<Byte> fileStatusList) {
        LambdaUpdateWrapper<FileBatch> wrapper = new LambdaUpdateWrapper();
        wrapper.set(FileBatch::getFileStatus, fileStatus);
        wrapper.eq(FileBatch::getId, id);
        wrapper.in(FileBatch::getFileStatus, fileStatusList);
        return update(wrapper);
    }
}
